// Support &, ", ', < and >, escape all other
// occurrences of '&'.
let _text = text.replace(/&(?!amp;|quot;|apos;|lt;|gt;)/g, '&');
+
// Support <b>, <i>, and <u>, escape anything else
// so it displays as raw markup.
- return _text.replace(/<(\/?[^biu]>|[^>\/][^>])/g, '<$1');
- } else {
- // Escape everything
- let _text = text.replace(/&/g, '&');
- return _text.replace(/</g, '<');
+ _text = _text.replace(/<(?!\/?[biu]>)/g, '<');
+
+ try {
+ Pango.parse_markup(_text, -1, '');
+ return _text;
+ } catch (e) {}
}
+
+ // !allowMarkup, or invalid markup
+ return GLib.markup_escape_text(text, -1);
}
function URLHighlighter(text, lineWrap, allowMarkup) {